package demo

import (
	"fmt"
	"log"
	"zimuzu_cvn_web_api/lib/grpcClient"
	"zimuzu_cvn_web_api/pkg/errno"
)

func Test() (err error) {
	//USDT-生成账户签名
	AmountCreateData := map[string]string{
		"uid":                   "5164708",
		"balance":               "300.000000",
		"frozen_balance":        "0.000000",
		"last_log_sign_string":  "6e3ef6eb3f1eb92faa03e63d6ea99400acdde567",
		"last_log_sign_version": "1",
	}
	AmountCreateResp, err := grpcClient.UsdtAmountCreate(AmountCreateData)
	if err != nil {
		log.Println(err)
		err = errno.SystemErr
		return err
	}
	AmountSignString := AmountCreateResp.SignString
	AmountSignVersion := AmountCreateResp.SignVersion
	fmt.Println(AmountSignString, AmountSignVersion)
	//USDT-校验账户签名
	AmountCheckData := map[string]string{
		"uid":"5164708",
	}
	AmountCheckResp, err := grpcClient.UsdtAmountCheck(AmountCheckData)
	fmt.Println(AmountCheckResp)
	if err != nil {
		log.Println(err)
		err = errno.SystemErr
		return err
	}
	if !AmountCheckResp.Ok {
		err = errno.DbSignError
		log.Println(err)
		return err
	}
	//USDT-生成日志签名
	LogCreateData := map[string]string{
		"uid":                   "5164708",
		"amount":                "200.000000",
		"balance":               "0.000000",
		"relate_id":             "2",
		"relate_table":          "cobo",
		"from":                  "0xfe8f73baab2b5a339a8da6780fefb858a10e9fdf",
		"to":                    "0xfe8c66752a53b71c763c019b80a6e104aba1d20a",
		"source":                "13",
		"last_log_sign_string":  "c9a49d3f2547995745bbe7c32f41dc77fa15cf36",
		"last_log_sign_version": "1",
	}
	LogCreateResp, err := grpcClient.UsdtLogCreate(LogCreateData)
	if err != nil {
		log.Println(err)
		err = errno.SystemErr
		return err
	}
	LogSignString := LogCreateResp.SignString
	LogSignVersion := LogCreateResp.SignVersion
	fmt.Println(LogSignString, LogSignVersion)
	//USDT-校验流水签名
	LogListCheckData := map[string]string{
		"uid":"5164708",
	}
	LogListCheckResp, err := grpcClient.UsdtLogListCheck(LogListCheckData)
	if err != nil {
		log.Println(err)
		err = errno.SystemErr
		return err
	}
	fmt.Printf("错误数 = %v\r\n", LogListCheckResp.ErrNum)
	fmt.Printf("每条流水签名是否正确，及正确的签名，数据结构以id为键的map: %v\r\n", LogListCheckResp.List)
	return nil
}
